﻿using AutoMapper;
using Modules.Entitys;
using Modules.Notify;
using Modules.System.Attachment;
using PmSoft;

namespace ManagementApi.Models.Notify
{
    /// <summary>
    /// 工人通知展示字段的
    /// </summary>
    public class WorkerNotifyDto
    {
        /// <summary>
        /// 系统通知Id 
        ///</summary>
        public string Id { get; set; }
        /// <summary>
        /// 通知标题 
        ///</summary>
        public string? Title { get; set; }
        /// <summary>
        /// 发布内容 
        ///</summary>
        public string? Content { get; set; }
        /// <summary>
        /// 已读次数 
        ///</summary>
        public int? ReadedNum { get; set; }
        /// <summary>
        /// 发布者 
        ///</summary>
        public string? Creator { get; set; }
        /// <summary>
        /// 发布时间 
        ///</summary>
        public DateTime? CreateTime { get; set; }
        /// <summary>
        /// 修改时间 
        ///</summary>
        public DateTime? UpdateTime { get; set; }

        /// <summary>
        /// 附件集合
        /// </summary>
        public IEnumerable<AttachmentInfo>? attachments { get; set; }

    }

    /// <summary>
    /// 扩展字段处理
    /// </summary>
    public static partial class WorkerNotifyExceptions
    {

        /// <summary>
        /// 转换Dto
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static WorkerNotifyDto AsWorkerNotifyDto(this WorkerNotify entity)
        {
            WorkerNotifyDto workerNotifyDto = new WorkerNotifyDto();
            var mapper = ServiceAccessor.GetService<IMapper>();
            var notifyAttachmentService = ServiceAccessor.GetService<NotifyAttachmentService>();
            mapper.Map(entity, workerNotifyDto);
            workerNotifyDto.attachments = notifyAttachmentService.GetWorkerAttachmentByNotifyId(entity.Id);
            return workerNotifyDto;
        }
    }
}
